package com.barunsw.bwf.dhtmlx_sample.tutorial6;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/tutorial6")
public class DhtmlxTutorial6Controller {
	@Autowired
	DhtmlxTutorial6Service dhtmlxTutorial6Service;
	
	@RequestMapping(value = "", method = RequestMethod.GET)
	public String tutorial6() {
		return "dhtmlx_tutorial/tutorial6";
	}
	
	@RequestMapping(value="/selectOne", method=RequestMethod.POST)
	public @ResponseBody DhtmlxTutorial6CustomerVo getOneCustomer(@RequestBody String oneId) throws Exception {
		long id = Long.parseLong(oneId);

		DhtmlxTutorial6CustomerVo oneCustomer = dhtmlxTutorial6Service.selectById(id);
		
		return oneCustomer;
	}
	
	@RequestMapping(value="/update", method=RequestMethod.POST)
	public @ResponseBody String insertContact(@RequestBody DhtmlxTutorial6CustomerVo customerVo) throws Exception {
		String resultStr= "성공";
		
		int result = dhtmlxTutorial6Service.update(customerVo);
		if ( result <= 0 ) {
			resultStr = "실패";
		}
		return resultStr;
	}
}
